﻿using MediatR;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using U.B.ErrorCode;
using U.B.WriteApi.Command.RabbitBWss;

namespace U.B.WriteApi.Controllers
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class rabbitController : ControllerBase
    {
        public readonly IMediator _mediator;

        public rabbitController(IMediator mediator)
        {
            _mediator = mediator;
        }
        /// <summary>
        /// 商品添加
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>
        /// 
        [HttpPost]
        public  ApiResult<object>AddProduct([FromBody] AddrabbitsCommand command)
        {
             return  _mediator.Send(command).Result;
        }
        /// <summary>
        /// 商品删除
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>
        /// 
        [HttpPost]
        public  ApiResult<int>DelProduct([FromBody]DelrabbitsCommand command)
        {
            return _mediator.Send(command).Result;
        }
        /// <summary>
        /// 商品更新
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>
        /// 
        [HttpPut]
        public ApiResult<object> UpdateProduct( UpdaterabbitsCommand command)
        {
            return _mediator.Send(command).Result;  
        }
        /// <summary>
        /// 图片上传
        /// </summary>
        /// <param name="file"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<IActionResult> UploadImages(IFormFile file)
        {
            try
            {
                var res = "wwwroot/Images/" + file.FileName;
                using (FileStream fs = new FileStream(res, FileMode.OpenOrCreate))
                {
                    file.CopyTo(fs);
                }
                return Ok("https://localhost:44372/Images/" + file.FileName);
            }
            catch (Exception)
            {

                throw;
            }
        }
        /// <summary>
        /// 批量删 
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>
        [HttpPost]
        public ApiResult<object>DeletesProduct(DelProductsCommand command)
        {
            return _mediator.Send(command).Result;
        }
        /// <summary>
        /// 添加养殖信息
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>
        /// 
        [HttpPost]
        public ApiResult<object> AddFrim([FromBody] AddFarmCommmand command)
        {
            return _mediator.Send(command).Result;
        }
        /// <summary>
        /// 健康信息添加
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>
        [HttpPost]
        public ApiResult<object>AddImmune([FromBody] AddImmuneCommand command)
        {
            return _mediator.Send(command).Result;
        }
        /// <summary>
        /// 企业信息添加
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>
        [HttpPost]
        public ApiResult<object> AddFirm([FromBody] AddFirmCommand command)
        {
            return _mediator.Send(command).Result;
        }
        /// <summary>
        /// 屠宰添加
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>
        [HttpPost]
        public ApiResult<object> AddKill([FromBody] AddKillCommmand command)
        {
            return _mediator.Send(command).Result;
        }
        /// <summary>
        /// 企业信息添加
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>
        [HttpPost]
        public ApiResult<object> AddFirms([FromBody] AddFirmsCommand command)
        {
            return _mediator.Send(command).Result;
        }
        /// <summary>
        /// 添加供应商
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>、
        /// 
        [HttpPost]
        public ApiResult<object> AddSupplier([FromBody] AddSupplierCommand command)
        {
            return _mediator.Send(command).Result;
        }
        /// <summary>
        /// 养殖信息修改
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>
        /// 
        [HttpPut]
        public ApiResult<object>UpdateFarm([FromBody] UpdateFarmCommmand command)
        {
            return _mediator.Send(command).Result;
        }
        /// <summary>
        /// 修改企业信息
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>
        /// 
        [HttpPut]
        public ApiResult<object> UPFirm( [FromBody] UpdateFirmCommand command)
        {
            return _mediator.Send(command).Result;
        }
        /// <summary>
        /// 屠宰信息修改
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>
        /// 
        [HttpPut]
        public ApiResult<object>UpdateKill([FromBody] UpdateKillCommmand command)
        {
            return _mediator.Send(command).Result;
        }
        /// <summary>
        /// 屠宰信息删除
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>
        /// 
        [HttpDelete]
        public ApiResult<object> DelKill([FromBody] DelKillCommmand command)
        {
            return _mediator.Send(command).Result;
        }
        /// <summary>
        /// 养殖信息删除
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>
        [HttpDelete]
        public ApiResult<object>DelFarm([FromBody] DelFarmCommmand command)
        {
            return _mediator.Send(command).Result;
        }
        /// <summary>
        ///照片添加
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>
        /// 
        [HttpPost]
        public ApiResult<object>AddPicture([FromBody] AddPicCommand command)
        {
                return _mediator.Send(command).Result;
        }
        /// <summary>
        ///照片添加
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>
        /// 
        [HttpPost]
        public ApiResult<object> AddAPicture( AddPicACommand command)
        {
            return _mediator.Send(command).Result;
        }
        /// <summary>
        ///产检图片修改
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>
        /// 
        [HttpPut]
        public ApiResult<object> UpdatePicture([FromBody] UpdatePicCommand command)
        {
            return _mediator.Send(command).Result;
        }
    }
}
